
<%@ page import="java.sql.*" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>

<head>

    <title>个人中心</title>
    <link rel="stylesheet" href="css/bookstrap.css">

    <script src="js/jquery.min.js"></script>
    <script src="js/bookstrap.js"></script>
    <script src="js/bookstrap.bundle.js"></script>
    <style>
        .container{
            margin-top: 20px;
        }
    </style>

</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <h3 style="text-align: center">欢迎来到个人主页！</h3>
            <a href="#modal-container-addUser" role="button" class="btn" data-toggle="modal">添加用户</a>
            <table class="table table-striped">
                <thead>
                <th>ID</th>
                <th>用户名</th>
                <th>性别</th>
                <th>年龄</th>
                <th>操作</th>
                </thead>
                <tbody>

<%
    if (session.getAttribute("username")==null){
        out.print("你尚未登陆，3秒之后跳转登陆页面");
        response.setHeader("refresh","3;url=login.jsp");
    }else{

    Class.forName("com.mysql.jdbc.Driver");


    String url="jdbc:mysql://localhost:3306/book";

    Connection connection=DriverManager.getConnection(url,"root","root");


    String sql ="select * from user ";

   //String sql="delete from user where id=3";

    //String sql = "update user set name=? where age=?";

    //String sql="insert into user(username,password,gender,age)values(?,?,?,?)";

    PreparedStatement ps =connection.prepareStatement(sql);


    ResultSet rs=ps.executeQuery();

    while (rs.next()){
        out.print("<tr>");
        out.print(
                "<td>"+rs.getInt("id")+"</td>"
                +"<td>"+rs.getString("username")+"</td>"
                +"<td>"+rs.getString("gender")+"</td>"
                +"<td>"+rs.getString("age")+"</td>"
                +"<td><a href ='delete.jsp?id="+rs.getInt("id")+"'>删除</a>"
                +"&nbsp;<a href='edit.jsp?id="+rs.getInt("id")+"'>编辑</a></td>");
        out.print("</tr>");
        }
        }
    %>
        </tbody>
        </table>
           <div class="modal fade" id="modal-container-addUser" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
               <div class="modal-dialog">
                   <div class="modal-content">
                       <div class="modal-header">

                           <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
                           <h4 class="modal-title" id="myModalLabel">添加用户</h4>
                       </div>
        <form role="form" method="post" action="add.jsp">
            <div class="modal-body">
                <div class="form-group">
                    <label>用户名：</label><input type="text" name="username" class="form-control" />
                </div>
                <div class="form-group">
                    <label>密码：</label><input type="password" name="password" class="form-control" />
                </div>
                <div class="form-group">
                    <label>性别：</label><input type="text" name="gender" class="form-control" />
                </div>
                <div class="form-group">
                    <label>年龄：</label><input type="text" name="age" class="form-control" />
                </div>
            </div>
            <div class="modal-footer">
                <botton class="btn btn-default" type="botton"  data-dismiss="modal">关闭</botton>
                <botton class="btn btn-primary" type="submit">添加</botton>
            </div>
        </form>
    </div>
</div>
</div>
</div>
</div>
</div>

</body>
</html>
